interface KHTMLElement {
    /**
     * 查找父元素
     * @returns 父元素
     */
    parent(): KHTMLElement;
    /**
     * 查找符合条件的父元素
     * @param selectors 选择器
     * @returns 父元素
     */
    parent(selectors: string): KHTMLElement;
}
{
    Object.defineProperty(KHTMLElement.prototype, 'parent', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: U.F.overloading('DOM-parent',
            {
                types: [Etype.string],
                fn: function (this: KHTMLElement, selectors: string) {
                    for (let i = 0; i < this.elements.length; i++) {
                        const ele = this.elements[i];
                        let ele_parent = ele.parentElement!;
                        for (; U.is(Etype.HTMLElement, ele_parent) && ele_parent !== document.body; ele_parent = ele_parent.parentElement!) {
                            if (ele_parent.matches(selectors)) {
                                return new KHTMLElement(ele_parent);
                            }
                        }
                    }
                    return new KHTMLElement();
                }
            },
            {
                types: [U.F.argType.optionalAny],
                fn: function (this: KHTMLElement) {
                    for (let i = 0; i < this.elements.length; i++) {
                        const ele = this.elements[i];
                        let ele_parent = ele.parentElement!;
                        if (U.is(Etype.HTMLElement, ele_parent) && ele_parent !== document.body) {
                            return new KHTMLElement(ele_parent);
                        }
                    }
                    return new KHTMLElement();
                }
            },
        )
    });
}
